//
//  RootTableViewController.m
//  JX_xialapicture
//
//  Created by lanou3g on 15/9/7.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootTableViewController.h"
#import "UIView+Extension.h"

@interface RootTableViewController ()

@property (strong, nonatomic) UIView *topView;
@property (nonatomic, assign) CGRect defaultTopViewRect;
@end

@implementation RootTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200)];
    headView.backgroundColor = [UIColor blackColor];
    UIImageView *topView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"6.jpeg"]];
    topView.frame = headView.frame;
    self.topView = topView;
    self.defaultTopViewRect = _topView.frame;
    [headView addSubview:topView];
    self.tableView.tableHeaderView = headView;
 
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = @"111";
    return cell;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offsetY = -scrollView.contentOffset.y;
    CGFloat oldH = self.defaultTopViewRect.size.height;
    CGFloat oldW = self.defaultTopViewRect.size.width;
    if (scrollView.contentOffset.y < 0) {
        CGFloat newH = oldH + offsetY;
        CGFloat newW = oldW * (newH/oldH);
        self.topView.frame = CGRectMake(0, 0, newW, newH);
        self.topView.center = CGPointMake(self.view.center.x, oldH - newH/2);
    } else {
//        CGFloat scale = (CGFloat)(oldH + offsetY) / oldH;
//        self.topView.height = oldH*scale;
//
//        NSLog(@"%f", oldH*scale);
        NSLog(@"1111");

        NSLog(@"44444");
        NSLog(@"master");
        
        
        NSLog(@"3333");
        NSLog(@"5555");
        NSLog(@"master");
        NSLog(@"!!!!!!");
        
        
        
        
    }
}






@end
